export default {
    set: (key, value, options) => {
        var cookieText = encodeURIComponent(key) + "=" + encodeURIComponent(value);
        Object.keys(options).forEach(item => {
            cookieText += `;${item}=${options[item]}`
        })

        document.cookie = cookieText
    },
    get: (key) => {
        const [
            cookieName,
            cookieStart,
            cookieValue
        ] = 
            [
              encodeURIComponent(key) + "=",
              document.cookie.indexOf(cookieName),
              ""
        ]
        if(cookieStart > -1) {
            var cookieEnd = document.cookie.indexOf(";", cookieStart);
            if(cookieEnd == -1) {
                cookieEnd = document.cookie.length;
            }
            cookieValue = decodeURIComponent(document.cookie.substring(cookieStart + cookieName.length, cookieEnd));
        }
        return cookieValue;
    },
    remove: (key) => {
        this.set(key, "", {
            maxAge:0
        });
    }
}